#------------------------------------------------------------------------------
# Project:     Multi-Programmer Game Demo
# Name:        game.py
# Purpose:     Setup and Main Loop
# 
# Authors:     Chris Spooner, Chris La-Roo
# Main Author: Chris Spooner
#
# Created:     11/30/2012
# Copyright:   (c) Chris Spooner 2012
# Licence:     New BSD
#------------------------------------------------------------------------------
import pygame, math, sys, Ball, Paddle
from Ball import Ball
from Paddle import Paddle
from Counter import Counter
#I WAS HELPED 1 time
pygame.init()

screenWidth = 800
screenHeight = 600

screenSize = screenWidth, screenHeight
screen = pygame.display.set_mode(screenSize)

ball1 = Ball(["ball1.png","ball2.png"], [-5,0], screenSize, 10)
ball1.place([500,300])
paddle1 = Paddle(['paddle1.png'], [0,0], screenSize, 10)
paddle1.place([10,300])
counter = Counter([700,25], screenSize)
counter1 = Counter([25,25], screenSize)
red = 0
green = 0
blue = 0
bgColor = red, green, blue
#                 player one key down
while True:
    for event in pygame.event.get():
        if event.type == pygame.QUIT: sys.exit()
        if event.type == pygame.KEYDOWN:
            if event.key == pygame.K_UP:
                paddle1.speed[1] = paddle1.speed[1] =-3
            if event.key == pygame.K_DOWN:
                paddle1.speed[1] = paddle1.speed[1] =3       
        if event.type == pygame.KEYUP:
            if event.key == pygame.K_UP:
                paddle1.speed[1] = paddle1.speed[1] = 0
            if event.key == pygame.K_DOWN:
                paddle1.speed[1] = paddle1.speed[1] = 0

              
    counter1.increase()         
    ball1.move()
    if ball1.wallCollide():
        counter.decrease()
        print counter.value

        
    paddle1.move()
    paddle1.wallCollide()
    
    counter.stop(0)
    counter1.set(0)
    ball1.paddleCollide(paddle1)
   


        
    screen.fill(bgColor)
    
    screen.blit(ball1.surface, ball1.rect)
    screen.blit(paddle1.surface, paddle1.rect)
    screen.blit(counter.surface, counter.rect)
#    screen.blit(counter1.surface, counter1.rect)
    pygame.display.flip()
    